<template>
  <div>
    <van-loading type="spinner" v-if="isShowLoading" />
    <van-pull-refresh v-model="isLoading" @refresh="onRefresh">
      <van-card @click="godetail(item.id)" v-for="item in NewsList" :key="item.id" :title="item.title" :thumb="item.img_url">
        <template slot="num">点击次数：{{item.click}}</template>
        <template slot="price">发表时间：{{item.add_time | formatDate}}</template>
      </van-card>
    </van-pull-refresh>
  </div>
</template>
<script>
export default {
  created () {
    this.getNewsList()
  },
  data () {
    return {
      NewsList: [],
      isShowLoading: true,
      count: 0,
      isLoading: false
    }
  },
  methods: {
    async getNewsList () {
      const { data: res } = await this.$http.get('/api/getnewslist')
      if (res.status !== 0) return this.$toast.fail('请求数据失败')
      this.NewsList = res.message
      this.isShowLoading = false
    },
    onRefresh () {
      setTimeout(() => {
        this.getNewsList()
        this.$toast('刷新成功')
        this.isLoading = false
      }, 500)
    },
    godetail (id) {
      this.$router.push('newsdetail/' + id)
    }
  }
}
</script>
<style scoped lang="less">
.van-loading {
  text-align: center
}
.van-card {
  margin-top: 20px;
  overflow-y: scroll;
  overflow-x: hidden
}
</style>
